﻿using Autofac;
using Micro.Modules.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Micro.Modules
{
    public static class ModuleExtensions
    {
        /// <summary>
        /// 获取所有模块信息
        /// </summary>
        public static List<BaseModule> GetAllBaseModules(this IServiceProvider provider)
        {
            List<BaseModule> list = provider.GetServices<BaseModule>().OrderBy(m => m.Order).ThenBy(m => m.GetType().FullName).ToList();
            return list;
        }
        /// <summary>
        /// 获取所有模块信息
        /// </summary>
        public static List<IModule> GetAllModule(this IServiceProvider provider)
        {
            List<IModule> list = provider.GetServices<IModule>().ToList();
            return list;
        }


        /// <summary>
        /// Autofac
        /// </summary>
        /// <param name="builder"></param>
        public static void AddAutofacConfigureContainer(this ContainerBuilder builder, IServiceProvider provider)
        {
            var modules = provider.GetAllModule();
            foreach (BaseModule module in modules)
            {
                module.AutofacConfigureContainer(builder);
            }
        }
    }
}
